package com.anjubao.parking.municipal.parkinglot.controller;

import com.anjubao.parking.municipal.common.dto.ApiResult;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingLotDeviceStatusDto;
import com.anjubao.parking.municipal.parkinglot.service.ParkingLotDeviceStatusService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 停车场设备运行情况controller
 *
 * @author zhuchunfeng
 * @date 2019/4/9 16:12
 */
@RestController
@RequestMapping("/devices")
@Api(value = "ParkingLotDeviceController", tags = {"设备监控"})
public class ParkingLotDeviceStatusController {

    @Resource
    private ParkingLotDeviceStatusService parkingLotDeviceStatusService;

    /**设备运行情况列表*/
    @ApiOperation(value = "设备运行情况列表")
    @GetMapping("/status")
    public ApiResult<List<ParkingLotDeviceStatusDto>> listDevices(@RequestParam(value = "page",defaultValue = "1") Integer page,
                                                                  @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                                  @RequestParam(value = "cityId", required = true) Integer cityId
                                                                  ) {
        IPage<ParkingLotDeviceStatusDto> parkingLotDeviceStatusDtoIPage = parkingLotDeviceStatusService.listDevicesStatus(page, pageSize , cityId);
        return ApiResult.success(parkingLotDeviceStatusDtoIPage.getRecords(), (int) parkingLotDeviceStatusDtoIPage.getTotal());
    }

    /**设备故障列表*/
    @ApiOperation(value = "设备故障列表")
    @GetMapping("/failures")
    public ApiResult<List<ParkingLotDeviceStatusDto>> queryFailureDevices(@RequestParam(value = "size", defaultValue = "100") Integer size,
                                                                          @RequestParam(value = "cityId", required = true) Integer cityId) {
        List<ParkingLotDeviceStatusDto> parkingLotDeviceStatusDtoIPage = parkingLotDeviceStatusService.listFailureDevice(size, cityId);
        return ApiResult.success(parkingLotDeviceStatusDtoIPage);
    }

}
